home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-12-02 | 5.9 KB | 194 lines | [TEXT/PJMM] |
- {AccessTimes adOn resource}
- {v1.0 November 1991}
-
- {Use AccessTimes to restrict the times that people can access your Macintosh}
- {Simply enter a time string against each user name & PowerLock will do the rest}
- {eg 0-24 gives 24 hour access, 16-20 gives access between 4:00pm and 8:59pm}
-
- {data is stored inside the PowerLock Prefs file active at the time the AddOn is used (in STR#200)}
-
- {Compile as a code resource, name=whatever, type ='adOn', ID=0, Attributes=00}
- {Save in file 'PowerLock Add-Ons' - file type 'adOn', creator 'PwrL'}
- {Store file inside the same folder as 'PowerLock Prefs'}
-
- {THINK Pascal requires the following build order:}
- {DRVRRuntime.lib (RSRCRuntime.lib for Think Pascal V4)}
- {Interface.lib}
- {AddOnIntf.p}
- {AccessTimer.p -this file}
-
- {You must also set the resource file to 'AccessTimer.rsrc' in Run Options...}
-
-
- unit AccessTimes;
- interface
-
- uses
- adOnIntf; {include any other units you want to use here}
-
- procedure main (req: integer; addOn: adOnPtr); {must be called 'main' & have these parameters}
-
- implementation
-
- const
- VERSION = 'AccessTimer, © Rohan Cook, v1.00, 2 Dec 91'; {change this to whatever you want the aReqVersion request to return}
-
-
- {Utility Procedures & Functions used by this Add-On}
- function Num2Str (num: longint): string;
- {converts numeric to string - uses Toolbox Procedure}
- var
- str: str255;
- begin
- NumToString(num, str);
- Num2Str := str
- end;
-
- function str2Num (str: str255): longint;
- {converts string to numeric - uses Toolbox Procedure}
- var
- num: longint;
- begin
- stringToNum(str, num);
- str2Num := num;
- end;
-
- function getDText (dlg: dialogPtr; item: integer): string;
- {given a dialog ptr and an item number return its text - only 255 chars are returned}
- var
- iType: integer;
- iHandle: handle;
- ibox: rect;
- tempStr: str255;
- begin
- getDItem(dlg, item, iType, iHandle, Ibox);
- getIText(iHandle, tempStr);
- getDText := tempStr;
- end;
-
- procedure setDText (dlg: dialogPtr; item: integer; str: string);
- {given dialog ptr, item number and a string - set the specified dialog item's text}
- {to that contained in STR}
- var
- iType: integer;
- iHandle: handle;
- ibox: rect;
- begin
- getDItem(dlg, item, iType, iHandle, Ibox);
- setIText(iHandle, str);
- end;
-
- procedure main (req: integer; addOn: adOnPtr);
- const
- FIRSTUSERNAME = 3;
- ACCESSDLOG = 200;
- TIMESTR = 200;
- var
- dlg: dialogPtr;
- item, i, users, user, prevResFile: integer;
- dash, fromHour, toHour: integer;
- d: dateTimeRec;
- s: str255;
- timesH, resH: handle;
- err: OSErr;
-
-
- procedure UsePrefs; {send callbacks to use the Prefs file, rather than the add0n file for resources}
- begin
- DoCBReq(cbReqPrefsResFile, addOn);
- UseResFile(addOn^.fileRef);
- end;
-
- procedure UseAddOn; {send callbacks to use the AddOn file for resources}
- begin
- DoCBReq(cbReqAddOnResFile, addOn);
- UseResFile(addOn^.fileRef);
- end;
-
- begin
-
- case req of {can receive any type of request as defined in the adOnIntf file - remember the OTHERWISE!}
-
- aReqPWOk: {password was OK, now let's check if it's within authorised times}
- begin
- prevResFile := CurResFile; {remember what Resource File was in use when we started}
- UsePrefs;
- DoCBReq(cbReqUsers, addOn); {see if we're multiple users - if not, ignore this addon}
- if str2num(addOn^.result) > 1 then
- begin
- DoCBReq(cbReqUserID, addOn); {Get userID of current User}
- user := str2num(addOn^.result);
- GetIndString(s, TIMESTR, user); {Get access times for this user from STR# resource}
- dash := pos('-', s); {strip start hour and end hour}
- fromHour := str2num(copy(s, 1, dash - 1));
- toHour := str2num(copy(s, dash + 1, length(s)));
- GetTime(d);
- if (dash <> 0) & ((d.hour < fromHour) or (d.hour > toHour)) then {if no dash in time setting, then ignore it}
- begin
- addOn^.request := 'You are not authorised to use this Macintosh at this time';
- DoCBReq(cbReqMsg, addOn);
- addOn^.continue := false;
- end;
- UseResFile(prevResFile); {important: restore the current resource file to how you found it!}
- end;
- end;
- aReqUserListBtn: {popup times dialog whenever the UserList button is pressed in the Prefs dialog}
- begin
- prevResFile := CurResFile;
- UseAddOn;
- dlg := GetNewDialog(accessDLOG, nil, pointer(-1)); {Get the AccessTimes dialog from the add-on resource fork}
- DoCBReq(cbReqUsers, addOn);
- users := str2num(addOn^.result);
- for i := 1 to users do
- begin
- addOn^.request := num2str(i);
- DoCBReq(cbReqUser, addOn);
- SetDText(dlg, FIRSTUSERNAME + i - 1, addOn^.result); {fill in all known usernames in the dialog}
- end;
- UsePrefs;
- for i := 1 to 5 do
- begin
- GetIndString(s, TIMESTR, i);
- SetDText(dlg, FIRSTUSERNAME + 5 + i - 1, s); {fill in current access time settings}
- end;
- ShowWindow(dlg);
- repeat
- modalDialog(nil, item);
- until (item = 1) or (item = 2);
- if item = 1 then {OK, so save new info}
- begin
- timesH := NewHandle(0);
- i := 5;
- err := ptrAndHand(@i, timesH, 2);
- {now build up a handle to a STR# in memory}
- for i := 1 to 5 do
- begin
- s := GetDText(dlg, FIRSTUSERNAME + 5 + i - 1); {get the access times from the dialog}
- err := ptrAndHand(@s, timesH, length(s) + 1);
- end;
- resH := GetResource('STR#', TIMESTR); {remove previous user lists}
- if resH <> nil then
- RmveResource(resH);
- AddResource(handle(timesH), 'STR#', TIMESTR, 'AccessTimes');
- WriteResource(handle(timesH));
- disposHandle(timesH);
- UpdateResFile(CurResFile);
- end;
- DisposDialog(dlg);
- UseResFile(prevResFile);
- end;
-
-
- aReqVersion: {returns your version information}
- begin
- addOn^.aoAOIFVers := aoIntfVersion; {*** ALWAYS INCLUDE THIS LINE ***}
-
- addOn^.result := VERSION;
- end;
-
- otherwise
- end;
- end;
-
-
- end.